/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package beans;

import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

/**
 *
 * @author machine
 */
@Stateless
public class PersonapeliculasFacade extends AbstractFacade<Personapeliculas> implements PersonapeliculasFacadeLocal {
    @PersistenceContext(unitName = "videosJEE-ejbPU")
    private EntityManager em;

    @Override
    protected EntityManager getEntityManager() {
        return em;
    }

    public PersonapeliculasFacade() {
        super(Personapeliculas.class);
    }

    @Override
    public List<Personapeliculas> buscarPersonasVideo(String idpelicula, String idpersona) {
        String condicion = "";
        
        if( idpersona != null ){
            condicion += " and p.idpersonas.idpersonas = " + idpersona + " ";
        }
        
        if( idpelicula != null ){
            condicion += " and p.idpeliculas.idpeliculas = " + idpelicula + " ";
        }
        
        Query q = em.createQuery( "SELECT p FROM Personapeliculas p WHERE p.idpersonapeliculas > 0 " + condicion + " ORDER BY p.idpeliculas " );
        return q.getResultList(); // or getSingleResult();
    }
    
}
